package com.kobeliu.entity;

public class Demo_3 {
    public static void main(String[] args) {
        int[] arr = {3,2,5,4,2,3,3};

        InsertSort(arr);
    }

    private static void InsertSort(int[] arr) {

        for (int i = 1; i < arr.length; i++) {
            int index = i;
            for (int j = i-1; j >-1 ; j--) {
                if(arr[j] > arr[index]){
                    swap(arr,index,j);
                    index = j;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    private static void swap(int[] arr, int i, int j) {
        arr[i] = arr[i]^arr[j];
        arr[j] = arr[i]^arr[j];
        arr[i] = arr[i]^arr[j];
    }
}
